<style lang="scss" scoped>
.picdate {
  .main {
    width: 84%;
    margin: 0 13% 0 13%;
    .head {
      margin: 30px 0 30px 0;
    }
  }
}
</style>
<template>
  <div class="picdate">
    <div class="main">
      <div class="head">
        <el-form :inline="true" :model="search" ref="searchForm">
          <el-form-item label="输入搜索:  " prop="name">
            <el-input v-model="search.name" placeholder="请输入相册名称" />
          </el-form-item>
          <el-button
            @click="
              search.current = 1;
              Getablum();
            "
            >搜索</el-button
          >
          <el-button @click="resetForm('searchForm')">重置</el-button>
          <el-button style="margin-left: 50px" @click="newPic()">
            新建相册</el-button
          >
        </el-form>
      </div>

      <div>
        <el-table :data="GetPicList" style="width: 100%">
          <el-table-column prop="id" label="编号"> </el-table-column>
          <el-table-column prop="name" label="相册名称"> </el-table-column>
          <el-table-column prop="description" label="描述"> </el-table-column>
          <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              icon="el-icon-edit-outline"
              style="color: #4c93ff"
               @click="visible=true;check(scope.row);"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              icon="el-icon-edit-outline"
              style="color: #4c93ff"
              @click="$router.push('/admin/assets/gallery/picList/' + scope.row.id)"
              >查看</el-button
            >
            <el-button
              type="text"
              size="small"
              icon="el-icon-edit-outline"
              style="color: #4c93ff"
              @click="delPic(scope.row.id)"
              >删除</el-button
            >
            </template>
            </el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagnations.currentPage"
          :page-size="pagnations.pageSize"
          :page-sizes="[5, 10, 15, 20]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagnations.total"
        >
        </el-pagination>
      </div>
    </div>
    <EditAlbum v-if="visible" @close="visible=false" :id="id" @editSuccess="this.Getablum();"></EditAlbum>
  </div>
</template>

<script>
import { getAblum ,DelPic} from "@/api/assetsdata";
import EditAlbum from "@/components/EditAlbum.vue"
export default {
  components:{
    EditAlbum
  },
  data() {
    return {
      visible:false,
      GetPicList: [],
      pagnations: {},
      search: { size: 10, current: 1, name: "" },
    };
  },
  created() {
    this.Getablum();
  },
  activated() {
    this.Getablum();
  },
  methods: {
    check(e) {
      console.log(e);
      this.id = e;
    },
    delPic(id){
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          DelPic(id).then((res) => {
            if (res && res.data && res.data.code === 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.Getablum();
            } else {
              this.$message({
                type: "success",
                message: res.data.msg || "删除失败",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    
    newPic() {
      this.$router.push("/admin/assets/gallery/addAlbum");
    },
    resetForm(searchForm) {
      this.search.createEnd = "";
      this.$refs[searchForm].resetFields();
      this.Getablum();
    },

    Getablum() {
      var search = {};
      for (var k in this.search) {
        if (this.search[k]) {
          search[k] = this.search[k];
        }
      }
      getAblum(search).then((res) => {
        console.log(res.data.data);
        this.GetPicList = res.data.data;
        this.pagnations = res.data.pagnation;
        // console.log(this.pagnation);
        this.pagnations.currentPage = this.pagnations.currentPage * 1;
        this.pagnations.pageSize = this.pagnations.pageSize * 1;
      });
    },
    // 分页发生变化
    handleSizeChange(val) {
      this.search.size = val;
      this.Getablum();
    },
    // 处理current变化
    handleCurrentChange(val) {
      // 当当前页发生变化时候更新 搜索条件的当前页
      // 获取数据
      this.search.current = val;
      this.Getablum();
    },
  },
};
</script>
